package com.mage.servlet;

import com.mage.bean.PageBean;
import com.mage.dao.ChongzhiDao;
import com.mage.dao.UserDao;
import com.mage.dao.impl.ChongzhiDaoImpl;
import com.mage.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/TodayStatistics")
public class TodayStatistics extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public TodayStatistics() {
        super();
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            //1. 获取需要显示的页码数
            int currentPage = 1;
            if(request.getParameter("currentPage")!=null) {  //.获取通过http协议提交过来的数据.
                currentPage =Integer.parseInt( request.getParameter("currentPage"));
            }

            //2. 根据指定的页数，去获取该页的数据回来

            ChongzhiDao service = new ChongzhiDaoImpl();  //.接口的实例化，也就是新声明一个userdao，他可以调用userdaoimpl中的所有方法

            //4.UserDaoImpl，就是对Dao接口方法的实现，分层的思想，降低耦合


            PageBean pageBean= service.todayStatistics(currentPage);
            request.setAttribute("pageBean", pageBean);
            //3. 跳转界面。
            request.getRequestDispatcher("/Super/Today.jsp").forward(request, response);
        }catch (Exception e) {
            // TODO: handle exception
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }


}
